const Sequelize = require("sequelize");
const databaseConfig = {
  host: "localhost",
  port: "3306",
  username: "root",
  password: "mWXS19971222@.",
  database: "sequelize",
};
const seqConf = {
  host: databaseConfig.host,
  dialect: "mysql",
  timezone: "+08:00",
  // protocol: 'tcp',    //  连接数据库使用的协议
  // omitNull: false,    //  null 是否通过SQL语句查询
  pool: {
    max: 5,
    min: 0,
    idle: 10000, //  连接空置时间（毫秒），超时后将释放连接
  },
  retry: {
    //  设置自动查询时的重试标志
    max: 3, //  设置重试次数
  },
  define: {
    timestamps: false,
  },
};
const sequelize = new Sequelize(
  databaseConfig.database,
  databaseConfig.username,
  databaseConfig.password,
  { ...seqConf } //这其实多此一举,因为外面一层对象里面在包装一层对象,解耦还是一层对象
);
module.exports = sequelize;
//参考:https://segmentfault.com/a/1190000019760817
